#include <thrust/device_vector.h>
#include <thrust/copy.h>
#include <thrust/reduce_by_keyvalue.hpp>
using namespace thrust;

#include <iostream>

int main()
{
  device_vector<size_t> key(5);
  device_vector<size_t> value(5);

  key[0] =3;
  key[1] =5;
  key[2] =6;
  key[3] =1;
  key[4] =7;
  

  value[0] =1;
  value[1] =4;
  value[2] =9;
  value[3] =5;
  value[4] =6;

  device_vector<size_t> result(10, std::numeric_limits<size_t>::max());

  std::cout <<"key: ";
  thrust::copy( key.begin(), key.end(), std::ostream_iterator<size_t>( std::cout, ","));
  std::cout <<std::endl;

  std::cout <<"value: ";
  thrust::copy( value.begin(), value.end(), std::ostream_iterator<size_t>( std::cout, ","));
  std::cout <<std::endl;

  
  thrust::reduce_by_keyvalue( key.begin(), key.end(), 
			      value.begin(), 
			      result.begin(), result.end());
  
  
  std::cout <<"result: ";
  thrust::copy( result.begin(), result.end(), std::ostream_iterator<size_t>( std::cout, ","));
  std::cout <<std::endl;
  
  return 0;
}
